# -*- coding: utf-8 -*-
import time

from numpy.ma.core import floor

from src.conf.conf import getConf
from src.jianghu.ThreadCarry import Carry

logId = 0
publicData = getConf(n=0)



class Debug(Carry):
    def __init__(self, thread_id, name, index, public_data,ignore_block):
        super().__init__(thread_id, name, index, public_data,ignore_block)
        self.logId=0
        self.dm.Reg(public_data["系统"]["注册码"],public_data["系统"]["附加码"])
        self.dmVersion = self.dm.Ver()
        self.log.info("大漠版本 " + self.dmVersion)
        display = "dx.graphic.3d.10plus"
        mouse = "dx.mouse.input.lock.api2|dx.mouse.position.lock.api|dx.mouse.position.lock.message|dx.mouse.state.message"
        #
        keypad = "dx.keypad.input.lock.api|dx.keypad.state.api|dx.keypad.api|dx.keypad.raw.input|dx.keypad.raw.input.active"
        public = "dx.public.active.api|dx.public.active.message|dx.public.active.api2"
        mode = 0
        self.data["武器装备"] = [[-1, "", -1], [-1, "", -1], [-1, "", -1], [-1, "", -1], [-1, "", -1], [-1, "", -1]]
        self.data["武器装备"] = []
        self.publicData["门派挑战选择配置"] = self.dm.GetDirPath(r"pic\门派挑战")
        self.data["是否在高昌"] = False
        self.data["高昌"] = {
            "1": False,
            "2": False,
            "3": False,
            "4": False,
        }
        self.data["任务"] = {
            "6": [r"书\6上采燕功.bmp", r"书\6上蜀道难牌法.bmp", r"书\6上心意气混元功.bmp", r"书\6红三光奇功.bmp"],
            "7": [r"书\7上地火功.bmp", r"书\7上袈裟伏魔功.bmp", r"书\7上金雁功.bmp", r"书\7上控鹤功.bmp",
                  r"书\7上释迦掷象功.bmp", r"书\7红七煞断脉封穴法.bmp", ],
            "9": [r"书\9上大力鹰抓功.bmp", r"书\9上闭穴功.bmp", r"书\9上泥鳅功.bmp", r"书\9红圣心诀.bmp"],
            "6全": [
                r"书\6上采燕功.bmp", r"书\6上蜀道难牌法.bmp", r"书\6上心意气混元功.bmp",
                r"书\6中采燕功.bmp", r"书\6中蜀道难牌法.bmp", r"书\6中心意气混元功.bmp",
                r"书\6下采燕功.bmp", r"书\6下蜀道难牌法.bmp", r"书\6下心意气混元功.bmp", ],
            "7全": [
                r"书\7上地火功.bmp", r"书\7上袈裟伏魔功.bmp", r"书\7上金雁功.bmp", r"书\7上控鹤功.bmp",
                r"书\7上释迦掷象功.bmp",
                r"书\7中地火功.bmp", r"书\7中袈裟伏魔功.bmp", r"书\7中金雁功.bmp", r"书\7中控鹤功.bmp",
                r"书\7中释迦掷象功.bmp",
                r"书\7下地火功.bmp", r"书\7下袈裟伏魔功.bmp", r"书\7下金雁功.bmp", r"书\7下控鹤功.bmp",
                r"书\7下释迦掷象功.bmp", ],
            "9全": [
                r"书\9上大力鹰抓功.bmp", r"书\9上闭穴功.bmp", r"书\9上泥鳅功.bmp",
                r"书\9中大力鹰抓功.bmp", r"书\9中闭穴功.bmp", r"书\9中泥鳅功.bmp",
                r"书\9下大力鹰抓功.bmp", r"书\9下闭穴功.bmp", r"书\9下泥鳅功.bmp", ],
            "6上品开启": False,
            "7上品开启": False,
            "9上品开启": False,

        }

        print()
    def BindDOTA2Game(self):
            dota2_hwnd = self.dm.FindWindow(self.publicData["dota2_class_name"], self.publicData["dota2_tittle"])

            n = 10
            self.log.info("开始绑定dota2")
            while n > 0:
                n -= 1
                self.hwnd = dota2_hwnd
                self.dm.SetWindowState(dota2_hwnd, 1)
                time.sleep(1)
                res, err_msg = self.dm.BindWindowEx(dota2_hwnd, self.publicData["系统"]["绑定模式"])
                self.log.info("游戏进程绑定窗口结果 %s 错误码 %s" % (res, err_msg))
                if res == 1:
                    n = 0
                    self.publicData["游戏线程大漠插件是否绑定"] = 1





    def run(self):
        self.first_init()
        self.BindDOTA2Game()
        time.sleep(1)
        self.first_init()
        tmp = self.publicData["主c"]["洗髓经残页"]
        x, y = self.publicData["系统"]["窗口位置"].split(",")
        self.dm.MoveWindow(self.hwnd, x, y)
        # self.dm.MoveWindow(self.hwnd, 0, 0)
        self.publicData["基础配置"]["角色"] = "主c"
        print("99999999999999999")
        self.ChooseAdventureNew2()
        # self.DotaAttack(65,667,402,319)
        # self.data["当前战功兑换层数"] = 12
        # # self.Adventure(12)
        # path = r"NPC选项\奇遇%02d.bmp" % 1
        # print(path)
        # self.DotaAttack(27,633, 144, 359)
        # self.DotaAttack(0, 0, 299,59)
        # print(is_get)
        # self.DotaBlink(39, 612, 779, 419,5)
        # print(is_get)
        # res=1
        # time.sleep(1)
        # for i in range(10):
        #     time.sleep(1)
        #     print(i)
        #     print(self.OcrSuiYinNum())
        #     print(self.OcrZhanGongNum())
        #     print(self.OcrGuBiNum())
        # res = self.AccessNPC(70, 662, 638, 319)
        # self.DotaCheckMoveAttack(18, 643, 800, 400, step=1, n=10)
        # self.DotaCheckMoveAttack(45, 660, 680, 300, step=1, n=10)
        # is_get = self.dm.SearchPngClick(950, 450, 1200, 680, r"存档\合成1.bmp|存档\合成2.bmp|存档\合成3.bmp", 0.9, 3, 0.1, 2, 5, 5)
        # self.SynthesisGemByLvs([1,2,3,4,5],handIn=True)
        # start=time.time()
        # self.dm.EnablePicCache(1)
        # for i in range(100):
        #     is_get = self.dm.SearchPngClick(0, 0, 1280, 720, "存档\进攻boss头像.bmp", 0.99, 1, 0, 0, 0, 0)
        # now=time.time()
        # self.log.info("花费时间 %s"%(now-start))
        # start = time.time()
        # for i in range(100):
        #     self.log.info(i)
        #     self.dm.dm.LeftClick()
        #     now = time.time()
        # self.log.info("花费时间 %s" % (now - start))
        # self.GetBackpackPic()
        # self.GetPublicBackpackPic()
        # self.GetBackpackPicLeft()
        # self.dm.DebugScreen("aaaaaaaaa")
        # self.GetHuangLingPic()
        # self.GetXinMoPic()
        # self.data["黄陵层数"]=10
        # check_path = self.dm.GetPicAbsPath("|".join(self.data["任务"]["9全"]))
        # self.Get9BossPic(self.data["宝石"] + "|" + check_path+"|"+self.data["背包空图片路径"]+"|"+self.data["other"])
        # print(res)
        # for i in range(100):
        #     self.dm.LeftClick(484,634,1)
        #     time.sleep(1)

        #
        #
        #
        # self.AdvanceAttack()
        #time.sleep(2)
        # print(self.dm.GetCursorShape())


        self.dm.UnBindWindow()

def remove_duplicates(lst):
    if not lst:
        return []
    result = []
    for num in lst:
        if num not in result:
            result.append(num)
    return result
def keep_exist(lst,path):
    result=[]
    for file_name in lst:
        file_path=os.path.join(path,file_name)
        if os.path.exists(file_path):
            result.append(file_name)
    return result

def make_conf2(path):
    result=[]
    with open(path, "r", encoding="utf-8") as f:
        res = yaml.safe_load(f.read())
        for i in res:
            result.append(i)
            result.append(i.replace("极品", "普通"))
            result.append(i.replace("极品", "垃圾"))
            result.append(i.replace("普通", "垃圾"))

    result =remove_duplicates(result)
    result= keep_exist(result,r"F:\py32x\jhpy\pic\装备")
    return result

def make_conf1(path):
    result=[]
    with open(path, "r", encoding="utf-8") as f:
        res = yaml.safe_load(f.read())
        for i in res:
            result.append(i)
        for i in res:
            result.append(i.replace("极品", "普通"))
        for i in res:
            result.append(i.replace("极品", "垃圾"))
        for i in res:
            result.append(i.replace("普通", "垃圾"))

    result =remove_duplicates(result)

    result= keep_exist(result,r"F:\py32x\jhpy\pic\装备")
    return result

def write_conf(path,data):
    result=[]
    with open(path, "w", encoding="utf-8") as f:
        x=yaml.dump(data,allow_unicode=True)
        f.write(x)

if __name__ == '__main__':
    x=int(0.999)
    print(x)
    main = Debug(1, "debug", 1, publicData, False)
    main.start()
